package com.blkkj.huan.Controller;


import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.iot.model.v20170420.QueryDeviceByNameRequest;
import com.aliyuncs.iot.model.v20170420.QueryDeviceByNameResponse;
import com.blkkj.huan.util.BaseTest;
import com.blkkj.huan.util.LogUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class queryDeviceByNameController extends BaseTest {


    @PostMapping("/queryDeviceByName")
    public String queryDeviceByName(String productKey, String deviceName){
        //查询单个设备信息
        queryDeviceByNameTest(productKey, deviceName);
        return "huan";
    }


    public static void queryDeviceByNameTest(String productKey, String deviceName) {
        QueryDeviceByNameRequest request = new QueryDeviceByNameRequest();
        request.setProductKey(productKey);
        request.setDeviceName(deviceName);
        QueryDeviceByNameResponse response = (QueryDeviceByNameResponse)executeTest(request);
        if (response != null && response.getSuccess() != false) {
            LogUtil.print("查询设备成功！ " + JSONObject.toJSONString(response));
        } else {
            LogUtil.error("查询设备失败！requestId:" + response.getRequestId() + "原因：" + response.getErrorMessage());
        }
    }
}
